package com.org.testproject;

import java.util.Random;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnTouchListener;

public class ShapeTest extends Activity implements OnTouchListener{
	class RenderView extends View implements OnTouchListener
	{
		Paint paint;
		Random rand = new Random();
		public int width = 0;
		public int height = 0;
		
		
		public RenderView(Context context) {
			super(context);
			// TODO Auto-generated constructor stub
			
			paint = new Paint();
		}
		
		public RenderView(Context context, int Width, int Height) {
			super(context);
			// TODO Auto-generated constructor stub
			
			paint = new Paint();
			
			width = Width;
			height = Height;
		}		
		
		protected void onDraw(Canvas canvas)
		{
			canvas.drawRGB(255, 255, 255);
			paint.setColor(Color.RED);
			canvas.drawLine(0, 0, canvas.getWidth() - 1, canvas.getHeight() - 1, paint);
			
			paint.setStyle(Style.STROKE);
			paint.setColor(0xff00ff00);
			//canvas.drawCircle(rand.nextInt(canvas.getWidth()) , rand.nextInt(canvas.getHeight()), 40, paint);
			canvas.drawCircle(width , height, 40, paint);
			
			Log.d("TouchText1", String.valueOf(width) + "," + String.valueOf(height));
			
			paint.setStyle(Style.FILL);
			paint.setColor(0x770000ff);
			canvas.drawRect(100,100,200,200, paint);
			invalidate();		
		}

		@Override
		public boolean onTouch(View v, MotionEvent event) {
			// TODO Auto-generated method stub
			switch(event.getAction())
			{
			case MotionEvent.ACTION_DOWN:
				//builder.append("down, ");
				break;
			case MotionEvent.ACTION_MOVE:
				//builder.append("move, ");
				break;
			case MotionEvent.ACTION_CANCEL:
				//builder.append("cancel, ");
				break;
			case MotionEvent.ACTION_UP:
				//builder.append("up, ");
				break;			
			}
			
			width = (int)event.getX();
			height = (int)event.getY();
			
			//builder.append(arg1.getX());
			//builder.append(", ");
			//builder.append(arg1.getY());
			
			//String text = builder.toString();
			
			Log.d("TouchText2", String.valueOf(width) + "," + String.valueOf(height));
			
			//textView.setText(text);
			
			return true;
		}
	}

	int width = 0;
	int height = 0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(new RenderView(this));
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		switch(event.getAction())
		{
		case MotionEvent.ACTION_DOWN:
			//builder.append("down, ");
			break;
		case MotionEvent.ACTION_MOVE:
			//builder.append("move, ");
			break;
		case MotionEvent.ACTION_CANCEL:
			//builder.append("cancel, ");
			break;
		case MotionEvent.ACTION_UP:
			//builder.append("up, ");
			break;			
		}
		
		width = (int)event.getX();
		height = (int)event.getY();
		
		//builder.append(arg1.getX());
		//builder.append(", ");
		//builder.append(arg1.getY());
		
		//String text = builder.toString();
		
		Log.d("TouchText3", String.valueOf(width) + "," + String.valueOf(height));
		
		//textView.setText(text);
		
		return true;
	}
	
	
}
